package cn.hycat.leetcode.middle;

import java.util.*;

/**
 * @author 吕泽浩业
 * @version 1.0
 */
public class L剑指Offer35复杂链表的复制 {
    class Node {
        int val;
        Node next;
        Node random;

        public Node(int val) {
            this.val = val;
            this.next = null;
            this.random = null;
        }
    }

    public Node copyRandomList(Node head) {
        Node cur = head;
        HashMap<Node, Node> map = new HashMap();
        while(cur != null) {
            map.put(cur, new Node(cur.val));
            cur = cur.next;
        }
        cur = head;
        Stack s = new Stack();
        Queue q = new LinkedList();
        while(cur != null) {
            map.get(cur).next = map.get(cur.next);
            map.get(cur).random = map.get(cur.random);
            cur = cur.next;
        }
        return map.get(head);
    }

    public static void main(String[] args) {
        int[] a = {1,3,2,5,4};
        sort(a);
        Arrays.stream(a).forEach(System.out::print);

        int m = 1;
        int n = 2;
        sortInt(m, n);
        System.out.println("m n 分别是"+ m +" h" + n );
    }
    public static void sort(int[] a) {
        for(int i = 0; i < a.length; i++) {
            for(int j = 0; j < a.length - 1 - i; j++) {
                if(a[j] > a[j + 1]) {
                    swap(a, j + 1, j);
                }
            }
        }
    }


    public static void sortInt(int a, int b) {
        int temp = a;
        a = b;
        b = temp;
    }

    public static void swap(int a[], int i, int j) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}
